#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>
typedef int StackDataType;
typedef struct Stack {
	StackDataType* head;
	int capacity;
	int size;
}Stack;
Stack* StackCreate() {
	Stack* tmp = (Stack*)malloc(sizeof(Stack));
	tmp->head = NULL;
	tmp->capacity = tmp->size = 0;
	return tmp;
}
void StackPush(Stack*tmp,StackDataType x) {
	if (tmp->capacity == tmp->size) {
		int newcapacity = tmp->capacity == 0 ? 4 : 2 * tmp->capacity;
		StackDataType* cur = (StackDataType*)realloc(tmp->head, newcapacity * sizeof(StackDataType));
		if (cur == NULL) {
			perror("StackPush:malloc");
			exit;
		}
		tmp->head = cur;
		tmp->capacity = newcapacity;
	}
	tmp->head[tmp->size] = x;
	tmp->size++;
}
StackDataType StackPop(Stack*tmp) {
	if (tmp->size == 0) {
		perror("StackPop:NULL");
		exit;
	}
	StackDataType s = tmp->head[tmp->size - 1];
	tmp->size--;
	return s;
}
void StackDestroy(Stack*tmp) {
	free(tmp->head);
	tmp->head = NULL;
	tmp->capacity = tmp->size = 0;
	free(tmp);
	tmp = NULL;
}
typedef struct Queue{
	Stack* stack1;
	Stack* stack2;
}MyQueue;

MyQueue* myQueueCreate() {
	MyQueue* queue = (MyQueue*)malloc(sizeof(MyQueue));
	queue->stack1 = StackCreate();
	queue->stack2 = StackCreate();
	return queue;
}

void myQueuePush(MyQueue* obj, int x) {
	assert(obj);
	StackPush(obj->stack1, x);
}

int myQueuePop(MyQueue* obj) {
	assert(obj);
	if (obj->stack2->size == 0) {
		while (obj->stack1->size != 0) {
			StackPush(obj->stack2, StackPop(obj->stack1));
		}
	}
	return StackPop(obj->stack2);
}

int myQueuePeek(MyQueue* obj) {
	assert(obj);
	if (obj->stack2->size == 0) {
		if (obj->stack1->size == 0) {
			perror("Peek:NULL");
			exit;
		}
		return obj->stack1->head[0];
	}
	return obj->stack2->head[obj->stack2->size - 1];
}

bool myQueueEmpty(MyQueue* obj) {
	assert(obj);
	return obj->stack1->size == 0 && obj->stack2->size == 0;
}

void myQueueFree(MyQueue* obj) {
	assert(obj);
	StackDestroy(obj->stack1);
	StackDestroy(obj->stack2);
	free(obj);
	obj = NULL;
}
int main() {

}